<?php

namespace App\Http\Resources\Customer;

use App\model\customer\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class CustomerResource extends JsonResource
{
    public static $wrap=null;
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'code'=>200,
            'res'=>[
                'customer_id'=>$this->customer_id,
                'name'=>$this->name ?? '',
                'address'=>$this->address ?? '',
                'wuye'=>$this->wuye_format ?? '',
                'hangye'=>$this->hangye_format ?? '',
                'area'=>$this->area_format ?? '',
                'peidian'=>$this->peidian_format ?? '',
                'xiaofang'=>$this->xiaofang_format ?? '',
                'huanping'=>$this->huanping_format ?? '',
                'hangye'=>$this->hangye_format ?? '',
                'qiuzu'=>$this->qiuzu_format ?? '',
                'source'=>$this->source_format ?? '',
                'created_at'=>Carbon::parse($this->created_at)->format('Y/m/d H:i'),
                'telephone'=>$this->telephone,
                'desc'=>$this->desc,
                'records'=>$this->records,
                'owner'=>$this->owner ?? '',
                'owner_name'=> $this->owner->name ?? '',
                 'create_owner_name'=>$this->create_user_name ?? $this->creater->name,
                'depart'=>$this->depart ?? ['id'=>0,'name'=>''],
                'status'=>$this->status,
                'code'=>$this->code,
                'area_id'=>$this->area_id,
                'hangye_id'=>$this->hangye_id,
                'peidian_id'=>$this->peidian_id,
                'xuqiu_id'=>$this->xuqiu_id,
                'source_id'=>$this->source_id,
                'group_id'=>$this->group_id,
                'huanping_id'=>$this->huanping_id,
                'wuye_id'=>$this->wuye_id,
                'xiaofang_id'=>$this->xiaofang_id,
                 'big_part_id'=>$this->big_part_id,
                'xuqiu'=>$this->xuqiu_format,

                'big_part'=>$this->bigDepart->name ?? '',
                 'follow_status'=>$this->follow_status,
                'mobiles'=>$this->mobiles->pluck('mobile'),
                'can_fenpei'=>$this->is_chongfen
              //  'can_fenpei'=>1
            ]
        ];
    }
}
